package com.fz.song.service.impl;


import com.fz.song.dao.BlogBannerMapper;
import com.fz.song.dao.BlogTypeMapper;
import com.fz.song.pojo.BlogBanner;
import com.fz.song.pojo.BlogLabel;
import com.fz.song.pojo.BlogType;
import com.fz.song.service.IBlogBannerService;
import com.fz.song.service.IBlogTypeService;
import com.fz.song.util.ResultObj;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogBannerServiceImpl implements IBlogBannerService {

    @Autowired
    private BlogBannerMapper blogBannerMapper;

    private static Log logger = LogFactory.getLog(BlogBannerServiceImpl.class);


    @Override
    public PageInfo<BlogBanner> getBlogLableListData(Integer page, int limit) {
        PageHelper.startPage(page, limit);
        List<BlogBanner> listData = blogBannerMapper.getBlogBannerListData();
        PageInfo<BlogBanner> pageInfo = new PageInfo<BlogBanner>(listData);
        return pageInfo;
    }

    @Override
    public BlogBanner getBlogBannerByid(String id) {
        return blogBannerMapper.selectByPrimaryKey(id);
    }

    @Override
    public ResultObj updateBlogBanner(BlogBanner blogBanner) {
        int i = blogBannerMapper.updateByPrimaryKeySelective(blogBanner);
        if (i == 1) {
            return ResultObj.ok("修改成功");
        }
        return ResultObj.error("修改失败");
    }

    @Override
    public ResultObj delBlogBanner(String id) {
        BlogBanner blogBanner = blogBannerMapper.selectByPrimaryKey(id);
        blogBanner.setDel(1);
        int i = blogBannerMapper.updateByPrimaryKeySelective(blogBanner);
        if (i == 1) {
            return ResultObj.ok("删除成功");
        }
        return ResultObj.error("删除失败");
    }

    @Override
    public ResultObj saveBlogBanner(BlogBanner blogBanner) {
        int i = blogBannerMapper.insertSelective(blogBanner);
        if (i == 1) {
            return ResultObj.ok("新增成功");
        }
        return ResultObj.error("新增失败");
    }

    @Override
    public List<BlogBanner> getBannerList() {
        List<BlogBanner> list = blogBannerMapper.getBlogBannerListData();
        return list;
    }
}
